package com.sc.nft.util;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

public class RedisKeyUtil {

    public static String redisKeyAssemble(String[] redisKey, String segmentation) {
        StringBuffer s = new StringBuffer();
        for (int i = 0; i < redisKey.length; i++) {
            s.append(redisKey[i]);
            if (!StrUtil.isEmpty(segmentation)) {
                s.append(segmentation);
            }
        }
        return s.substring(0, s.length() - 1);
    }

    public static String redisKeyAssemble(Object[] redisKey, String segmentation) {
        StringBuffer s = new StringBuffer();
        for (int i = 0; i < redisKey.length; i++) {
            s.append(redisKey[i]);
            if (!StrUtil.isEmpty(segmentation)) {
                s.append(segmentation);
            }
        }
        String ss = s.toString();
        if (!StrUtil.isEmpty(segmentation)) {

            ss = ss.substring(0, s.length() - 1);
        }
        return ss;
    }

    public static boolean isJsonArr(String value) {
        if (StrUtil.isEmpty(value)) {
            return false;
        }
        Boolean isArr = Convert.toStr(value.charAt(0)).contains("[") && Convert.toStr(value.charAt(value.length() - 1)).contains("]");
        return isArr;
    }

    public static boolean isJsonObj(String value) {
        if (StrUtil.isEmpty(value)) {
            return false;
        }
        Boolean isArr = Convert.toStr(value.charAt(0)).contains("{") && Convert.toStr(value.charAt(value.length() - 1)).contains("}");
        return isArr;
    }
}
